package main

import (
	"fmt"
	"io"
	"net"
	"net/http"
	"os"
	"time"
)

func isPortOpen(host string, port int, timeout time.Duration) bool {
	address := net.JoinHostPort(host, fmt.Sprintf("%d", port))
	conn, err := net.DialTimeout("tcp", address, timeout)
	if err != nil {
		return false
	}
	defer conn.Close()
	return true
}

func get_body(url string) {
	// 发送GET请求
	resp, err := http.Get(url)
	if err != nil {
		fmt.Println("发送请求时出错:", err)
		return
	}
	defer resp.Body.Close()

	// 检查响应状态码
	if resp.StatusCode != http.StatusOK {
		fmt.Printf("请求失败，状态码: %d\n", resp.StatusCode)
		return
	}

	// 读取响应体
	body, err := io.ReadAll(resp.Body)
	if err != nil {
		fmt.Println("读取响应体时出错:", err)
		return
	}

	// 打印响应体
	fmt.Println("响应体:")
	fmt.Println(string(body))
}

func main() {
	fmt.Println("Hello, 世界")
	get_body(fmt.Sprintf("https://%s", os.Getenv("TEST_URL")))
	fmt.Println(isPortOpen(os.Getenv("MYSQL_HOST"), 3306, time.Second*7))
	time.Sleep(time.Hour * 24)
}
